package com.csk.zsk.compents.dao.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.csk.zsk.commons.dao.impl.BaseHibernateDao;
import com.csk.zsk.compents.dao.BookResourceDao;
import com.csk.zsk.compents.entity.BookResource;

@Repository
public class BookResourceDaoImpl extends BaseHibernateDao<BookResource, String> implements BookResourceDao {

	@Override
	public List<BookResource> searchBookResource(String title, String userName, Date startDate, Date endDate) {
		return find("from BookResource b where b.title like ? and b.userName like ? and b.time between ? and ?", "%"
				+ title + "%", "%" + userName + "%", startDate, endDate);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<BookResource> getBookResources(String userId, Integer num) {
		return createQuery("from BookResource b where b.userId = ? order by b.time desc", userId).setMaxResults(num)
				.list();
	}

}
